package com.xiaozhaovip.demo.intf.mapper;

import com.xiaozhaovip.demo.intf.entity.YueQiLaiInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 活动信息 持久层
 *
 * @author Cauli
 */
@Mapper
public interface YueQiLaiInfoServiceMapper {
    @Insert("insert into yue_activity_info(Title, CategoryId, PublishUserId, HighLight, Content, Status, Images, AddressType, CityId, Address," +
            "BeginTime, EndTime, LeastJoinNum, MostJoinNum, JoinNum, CollectionNum, AddTime, UpdateTime, UserIp)" +
            "values(#{title}, #{categoryId}, #{publishUserId}, #{highLight}, #{content}, #{status}, #{images}, #{addressType}, #{cityId}, #{address}," +
            "#{beginTime}, #{endTime}, #{leastJoinNum}, #{mostJoinNum}, #{collectionNum}, #{joinNum}, now(), now(), #{userIp})")
    int insert(YueQiLaiInfo info);

    @Select("select * from yue_activity_info where Id = #{id}")
    YueQiLaiInfo loadById(int id);

    @Update("update yue_activity_info set Status = #{status}, UpdateTime = now() where id = #{id}")
    int update(YueQiLaiInfo info);

    @Update("update yue_activity_info set CollectionNum = CollectionNum + 1, UpdateTime = now() where id = #{id}")
    int incrCollectNumById(int id);

    @Update("update yue_activity_info set CollectionNum = CollectionNum - 1, UpdateTime = now() where id = #{id}")
    int decrCollectNumById(int id);

    @Update("update yue_activity_info set JoinNum = JoinNum + 1,  UpdateTime = now() where id = #{id}")
    int incrJoinNumById(int id);

    @Update("update yue_activity_info set JoinNum = JoinNum - 1, UpdateTime = now() where id = #{id}")
    int decrJoinNumById(int id);

    @Select("select LAST_INSERT_ID()")
    int getLastInsertId();
}
